package com.bjpowernode.crm.service.impl;

import com.bjpowernode.crm.mapper.TransMapper;
import com.bjpowernode.crm.pojo.Page;
import com.bjpowernode.crm.pojo.Trans;
import com.bjpowernode.crm.service.TransService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class TransServiceImpl implements TransService {
    @Resource
    private TransMapper transMapper;
    @Override
    public void getTrans(Page page, Map map) {
        Integer totalRows = transMapper.getCount(map);
        page.setTotalRows(totalRows);

        Integer totalPages =(totalRows-1)/page.getRowsPerPage()+1;
        page.setTotalPages(totalPages);

        Integer index =(page.getCurrentPage()-1)*page.getRowsPerPage();
        List<Trans> data =transMapper.getAllTrans(index,page.getRowsPerPage(),map);
        page.setData(data);
    }

    @Override
    public Trans getAll(String id) {
        return transMapper.getAll(id);
    }
}
